import sys

from PySide2.QtCore import Qt
from PySide2.QtWidgets import (
    QApplication,
    QHBoxLayout,
    QLabel,
    QMainWindow,
    QPushButton,
    QStackedLayout,
    QVBoxLayout,
    QWidget,
    )

from color_widget import ColorWidget

class MainWindow(QMainWindow):
    def __init__(self):
        super().__init__()
        
        self.setWindowTitle("Stack Layout Sample")
        self.setFixedSize(500, 300)
        
        button_layout = QHBoxLayout()

        btn = QPushButton("red")
        btn.pressed.connect(self.activate_tab_1)
        button_layout.addWidget(btn)

        btn = QPushButton("green")
        btn.pressed.connect(self.activate_tab_2)
        button_layout.addWidget(btn)

        btn = QPushButton("yellow")
        btn.pressed.connect(self.activate_tab_3)
        button_layout.addWidget(btn)
        
        self.stacklayout = QStackedLayout()
        self.stacklayout.addWidget(ColorWidget("red"))
        self.stacklayout.addWidget(ColorWidget("green"))
        self.stacklayout.addWidget(ColorWidget("yellow"))

        pagelayout = QVBoxLayout()
        pagelayout.addLayout(button_layout)
        pagelayout.addLayout(self.stacklayout)

        widget = QWidget()
        widget.setLayout(pagelayout)
        self.setCentralWidget(widget)
        
        
    def activate_tab_1(self):
        self.stacklayout.setCurrentIndex(0)
    
    def activate_tab_2(self):
        self.stacklayout.setCurrentIndex(1)
    
    def activate_tab_3(self):
        self.stacklayout.setCurrentIndex(2)

app = QApplication(sys.argv)
window = MainWindow()
window.show()
app.exec_()